package com.vm.osm.business.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.gson.JsonObject;
import com.vm.osm.business.dao.*;
import com.vm.osm.business.dto.CreateNotifyReq;
import com.vm.osm.business.dto.req.orderInst.*;
import com.vm.osm.business.dto.rsp.customer.Customer;
import com.vm.osm.business.dto.rsp.failOrder.OrderAccessoryInfo;
import com.vm.osm.business.dto.rsp.failOrder.OrderSolutionPhoto;
import com.vm.osm.business.dto.rsp.orderInst.OrderInfo;
import com.vm.osm.business.dto.rsp.orderInst.RspOrderPage;
import com.vm.osm.business.entity.*;
import com.vm.osm.business.service.IMyOrderInfoService;
import com.vm.osm.business.util.*;
import com.vma.eams.spring.boot.log.LogCollector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * Created by chenzui on 2018/3/23.
 */
@Service
public class MyOrderInfoServiceImpl implements IMyOrderInfoService {

    @Autowired
    private OsmOrderFailureMapper osmOrderFailureMapper;

    @Autowired
    private OsmOrderFlowMapper osmOrderFlowMapper;

    @Autowired
    private OsmOrderLogMapper osmOrderLogMapper;

    @Autowired
    private OsmOrderPhotoMapper osmOrderPhotoMapper;

    @Autowired
    private OsmOrderFeeInfoMapper osmOrderFeeInfoMapper;

    @Autowired
    private OsmOrderAccessoryMapper osmOrderAccessoryMapper;

    @Autowired
    private OsmServerProviderMapper osmServerProviderMapper;

    @Autowired
    private NotifyUtil notifyUtil;

    @Override
    public RspOrderPage queryMyOrders(ReqGetMyOrder reqGetMyOrder) {

        RspOrderPage rspOrderPage = new RspOrderPage();
        List<OrderInfo> dataList;
        Page page = PageHelper.startPage(reqGetMyOrder.getPage_num(),reqGetMyOrder.getPage_size(),true);
        if(reqGetMyOrder.getFail_type_id() != null && !"".equals(reqGetMyOrder.getFail_type_id())){
            dataList = osmOrderFailureMapper.queryMyFailOrders(reqGetMyOrder);
        }else {
            dataList = osmOrderFailureMapper.queryMyOrders(reqGetMyOrder);
        }

        rspOrderPage.setData_list(dataList);
        rspOrderPage.setTotal_num(page.getTotal());
        rspOrderPage.setPage_num(page.getPageNum());
        rspOrderPage.setPage_size(page.getPageSize());
        return rspOrderPage;
    }

    @Override
    public void agree(String orderId, String staffId, String staffName,String headIcon) {
        OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(orderId);
        order.setStatus("6");//处理中
        order.setModifyTime(new Date());
        order.setAcceptStaffId(staffId);
        order.setAcceptStaffName(staffName);
        order.setAcceptTime(new Date());
        osmOrderFailureMapper.updateByPrimaryKeySelective(order);

        //记录操作流程节点
        OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
        osmOrderFlow.setSimpleDesc("接单");
        osmOrderFlow.setOperateUserId(staffId);
        osmOrderFlow.setId(UuidUtil.getRandomUuid());
        osmOrderFlow.setStatus(new Byte("1"));
        osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setOperateUserName(staffName);
        osmOrderFlow.setOrderId(orderId);
        osmOrderFlow.setOperateUserIcon(headIcon);
        osmOrderFlowMapper.insertSelective(osmOrderFlow);
        LogCollector.INSTANCE.put("工单号",order.getOrderNbr());

    }

    @Override
    public void disagree(String orderId, String type, String reason,String staffId, String staffName, String headIcon) {
        OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(orderId);
        order.setStatus("3");//等待分配
        order.setModifyTime(new Date());
        order.setAcceptStaffId(staffId);
        osmOrderFailureMapper.updateByPrimaryKeySelective(order);

        //记录操作流程节点
        OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
        osmOrderFlow.setSimpleDesc("拒绝接单"+reason);
        osmOrderFlow.setOperateUserId(staffId);
        osmOrderFlow.setId(UuidUtil.getRandomUuid());
        osmOrderFlow.setStatus(new Byte("1"));
        osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setOperateUserName(staffName);
        osmOrderFlow.setOrderId(orderId);
        osmOrderFlow.setOperateUserIcon(headIcon);
        osmOrderFlow.setRefuseType(Integer.valueOf(type));
        osmOrderFlow.setRefuseReason(reason);
        osmOrderFlowMapper.insertSelective(osmOrderFlow);

        LogCollector.INSTANCE.put("工单号",order.getOrderNbr());
    }

    @Override
    public void updateOrderFailure(ReqDealOrderFailure reqDealOrderFailure) {
        OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(reqDealOrderFailure.getOrder_id());
        boolean flag = false;
        String oldId = "";
        if(order.getIsFromOut() != null && order.getIsFromOut().equals(1)){
            OsmOrderFailure old = osmOrderFailureMapper.selectByPrimaryKey(order.getOutOrderId());
            old.setStatus("7");
            osmOrderFailureMapper.updateByPrimaryKeySelective(old);

            osmOrderAccessoryMapper.deleteAccessoryInfosByOrderId(old.getId());
            osmOrderFeeInfoMapper.deleteFeeInfosById(old.getId());
            osmOrderPhotoMapper.deletePhotosByOrderId(old.getId());
            osmOrderLogMapper.deleteLogByOrderId(old.getId());

            oldId = old.getId();

            flag = true;
        }

        //删除无效数据
        osmOrderAccessoryMapper.deleteAccessoryInfosByOrderId(reqDealOrderFailure.getOrder_id());
        osmOrderFeeInfoMapper.deleteFeeInfosById(reqDealOrderFailure.getOrder_id());
        osmOrderPhotoMapper.deletePhotosByOrderId(reqDealOrderFailure.getOrder_id());
        osmOrderLogMapper.deleteLogByOrderId(reqDealOrderFailure.getOrder_id());


        order.setDealLongTime(reqDealOrderFailure.getDeal_long_time()==null?new BigDecimal(0):BigDecimal.valueOf(reqDealOrderFailure.getDeal_long_time()));

        Date date = new Date();

        //记录解决方案
        OsmOrderLog log = new OsmOrderLog();
        log.setOrderId(reqDealOrderFailure.getOrder_id());
        log.setCreateTime(date);
        log.setUpdateTime(date);
        log.setId(UuidUtil.getRandomUuid());
        log.setReasonAnalysis(reqDealOrderFailure.getReason_analysis());
        log.setSolution(reqDealOrderFailure.getSolution());
        osmOrderLogMapper.insertSelective(log);

        if(flag){
            OsmOrderLog log2 = log;
            log2.setOrderId(oldId);
            log2.setId(UuidUtil.getRandomUuid());
            osmOrderLogMapper.insertSelective(log2);

        }

        //记录解决步骤的图片
        List<OrderSolutionPhoto> photos = reqDealOrderFailure.getPhotos();
        OsmOrderPhoto record = new OsmOrderPhoto();
        if(photos != null && !photos.isEmpty()){
            for (OrderSolutionPhoto photo: photos) {
                record.setId(UuidUtil.getRandomUuid());
                record.setCreateTime(date);
                record.setUpdateTime(date);
                record.setIndexs(photos.indexOf(photo));
                record.setOrderId(reqDealOrderFailure.getOrder_id());
                record.setPhotoName(photo.getPhoto_name());
                record.setUrl(photo.getUrl());
                record.setSize(photo.getSize());
                osmOrderPhotoMapper.insertSelective(record);

                if(flag){
                    OsmOrderPhoto temp = record;
                    temp.setOrderId(oldId);
                    temp.setId(UuidUtil.getRandomUuid());
                    osmOrderPhotoMapper.insertSelective(temp);

                }
            }
        }

        OsmOrderFeeInfo feeInfo = new OsmOrderFeeInfo();
        //记录人工费用
        feeInfo.setOrderId(reqDealOrderFailure.getOrder_id());
        feeInfo.setCreateTime(date);
        feeInfo.setUpdateTime(date);
        feeInfo.setId(UuidUtil.getRandomUuid());
        feeInfo.setStatus(new Byte("1"));
        feeInfo.setFeeDesc("人工费用");
        feeInfo.setFee(reqDealOrderFailure.getPeople_fee());
        osmOrderFeeInfoMapper.insertSelective(feeInfo);
        if(flag){
            OsmOrderFeeInfo temp = feeInfo;
            temp.setOrderId(oldId);
            temp.setId(UuidUtil.getRandomUuid());
            osmOrderFeeInfoMapper.insertSelective(temp);

        }
        //记录配件费用
        feeInfo.setOrderId(reqDealOrderFailure.getOrder_id());
        feeInfo.setCreateTime(date);
        feeInfo.setUpdateTime(date);
        feeInfo.setId(UuidUtil.getRandomUuid());
        feeInfo.setStatus(new Byte("1"));
        feeInfo.setFeeDesc("配件费用");
        feeInfo.setFee(reqDealOrderFailure.getAccessory_fee());
        osmOrderFeeInfoMapper.insertSelective(feeInfo);
        if(flag){
            OsmOrderFeeInfo temp =feeInfo;
            temp.setOrderId(oldId);
            temp.setId(UuidUtil.getRandomUuid());
            osmOrderFeeInfoMapper.insertSelective(temp);

        }

        //记录配件信息
        List<OrderAccessoryInfo> accessories = reqDealOrderFailure.getAccessory();
        if(accessories != null && !accessories.isEmpty()){
            OsmOrderAccessory accessoryRecord = new OsmOrderAccessory();
            for (OrderAccessoryInfo accessory:accessories) {
                accessoryRecord.setId(UuidUtil.getRandomUuid());
                accessoryRecord.setAccessoryNo(accessory.getAccessory_no());
                accessoryRecord.setAccessoryType(accessory.getAccessory_type());
                accessoryRecord.setBranch(accessory.getBranch());
                accessoryRecord.setFroms(accessory.getFroms());
                accessoryRecord.setNumber(accessory.getNumber());
                accessoryRecord.setPrice(accessory.getTotal_price());
                accessoryRecord.setTotalPrice(accessory.getTotal_price());
                accessoryRecord.setType(accessory.getType());
                accessoryRecord.setOrderId(reqDealOrderFailure.getOrder_id());
                accessoryRecord.setSpec(accessory.getSpec());
                accessoryRecord.setIsAdd(accessory.getIs_add());
                osmOrderAccessoryMapper.insertSelective(accessoryRecord);
                if(flag){
                    OsmOrderAccessory temp =accessoryRecord;
                    temp.setOrderId(oldId);
                    temp.setId(UuidUtil.getRandomUuid());
                    osmOrderAccessoryMapper.insertSelective(temp);

                }
            }
        }

        if("2".equals(reqDealOrderFailure.getType())){//保存工单信息。非草稿
            //记录操作流程节点
            OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
            osmOrderFlow.setSimpleDesc("处理完成,填写工单信息");
            osmOrderFlow.setOperateUserId(reqDealOrderFailure.getStaff_id());
            osmOrderFlow.setId(UuidUtil.getRandomUuid());
            osmOrderFlow.setStatus(new Byte("1"));
            osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setOperateUserName(reqDealOrderFailure.getStaff_name());
            osmOrderFlow.setOrderId(reqDealOrderFailure.getOrder_id());
            osmOrderFlow.setOperateUserIcon(reqDealOrderFailure.getHead_icon());
            osmOrderFlowMapper.insertSelective(osmOrderFlow);
            order.setStatus("7");//处理完成
            osmOrderFailureMapper.updateByPrimaryKeySelective(order);


            String content = "工单【"+order.getOrderTitle() +"】已处理完成，请确认处理结果";
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("order_type","1");
            jsonObject.addProperty("type","1");
            jsonObject.addProperty("order_id",order.getId());
            String extra = GsonUtil.toJson(jsonObject);
            String title = "工单处理完成";
            String sender = reqDealOrderFailure.getStaff_id();
            String target = order.getSubmitStaffId();
            CreateNotifyReq createNotifyReq = new CreateNotifyReq(content,extra,title,sender,target,order.getEnterpriseId());

            notifyUtil.send(createNotifyReq);

            LogCollector.INSTANCE.put("工单号",order.getOrderNbr());
        }else {
            //保存草稿。工单状态不变;
            LogCollector.INSTANCE.put("作废记录",order.getOrderNbr());

        }
    }

    @Override
    public void turn(ReqTurnOrder reqTurnOrder) {
        OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
        String desc = "维护人员"+reqTurnOrder.getStaff_name()+"在"+ DateFormatUtils.formate(new Date())+
                "转单给"+reqTurnOrder.getTarget_staff_name()+"备注："+reqTurnOrder.getRemark();
        osmOrderFlow.setSimpleDesc(desc);
        osmOrderFlow.setOperateUserId(reqTurnOrder.getStaff_id());
        osmOrderFlow.setId(UuidUtil.getRandomUuid());
        osmOrderFlow.setStatus(new Byte("1"));
        osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setOperateUserName(reqTurnOrder.getStaff_name());
        osmOrderFlow.setOrderId(reqTurnOrder.getOrder_id());
        osmOrderFlow.setOperateUserIcon(reqTurnOrder.getHead_icon());
        osmOrderFlowMapper.insertSelective(osmOrderFlow);

        OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(reqTurnOrder.getOrder_id());
        order.setStatus("5");//转单-->待接单
        order.setAcceptStaffId(reqTurnOrder.getTarget_staff_id());
        osmOrderFailureMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public List<Customer> queryProviders(String enterpriseId) {
        return osmServerProviderMapper.queryByPage(enterpriseId,null,null);
    }

    @Override
    public void up(ReqUpOrder reqUpOrder) {
        String orderId = reqUpOrder.getOrder_id();
        OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(orderId);
        order.setStatus("11");
        order.setModifyTime(new Date());
        osmOrderFailureMapper.updateByPrimaryKeySelective(order);

        //记录操作流程节点
        OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
        osmOrderFlow.setSimpleDesc("上报工单"+ (StringUtils.isEmpty(reqUpOrder.getRemark())?"":":"+reqUpOrder.getRemark()));
        osmOrderFlow.setOperateUserId(reqUpOrder.getStaff_id());
        osmOrderFlow.setId(UuidUtil.getRandomUuid());
        osmOrderFlow.setStatus(new Byte("1"));
        osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setOperateUserName(reqUpOrder.getStaff_name());
        osmOrderFlow.setOrderId(orderId);
        osmOrderFlow.setOperateUserIcon(reqUpOrder.getHead_icon());
        osmOrderFlowMapper.insertSelective(osmOrderFlow);

        LogCollector.INSTANCE.put("工单号",order.getOrderNbr());
    }

    @Override
    public void back(ReqBackOrder reqBackOrder) {
        String orderId = reqBackOrder.getOrder_id();
        OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(orderId);
        order.setStatus("8");//误报，直接回已完成状态
        order.setModifyTime(new Date());
        osmOrderFailureMapper.updateByPrimaryKeySelective(order);

        //记录操作流程节点
        OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
        osmOrderFlow.setSimpleDesc("误报"+reqBackOrder.getRemark());
        osmOrderFlow.setOperateUserId(reqBackOrder.getStaff_id());
        osmOrderFlow.setId(UuidUtil.getRandomUuid());
        osmOrderFlow.setStatus(new Byte("1"));
        osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setOperateUserName(reqBackOrder.getStaff_name());
        osmOrderFlow.setOrderId(orderId);
        osmOrderFlow.setOperateUserIcon(reqBackOrder.getHead_icon());
        osmOrderFlowMapper.insertSelective(osmOrderFlow);

        LogCollector.INSTANCE.put("工单号",order.getOrderNbr());
    }

    @Override
    public void dealUpOrder(ReqAssignOrder reqAssignOrder, HttpServletRequest request) {
        String type = reqAssignOrder.getTarget_type();
        String orderId = reqAssignOrder.getOrder_id();
        OsmOrderFailure orderFailure = osmOrderFailureMapper.selectByPrimaryKey(orderId);

        if("1".equals(type)){
            orderFailure.setAcceptStaffId(reqAssignOrder.getTarget_id());
            orderFailure.setStatus("5");
            orderFailure.setModifyTime(new Date());
            osmOrderFailureMapper.updateByPrimaryKeySelective(orderFailure);

            //记录操作流程节点
            OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
            osmOrderFlow.setSimpleDesc("指派给："+reqAssignOrder.getTarget_name());
            osmOrderFlow.setOperateUserId(reqAssignOrder.getOperate_staff_id());
            osmOrderFlow.setId(UuidUtil.getRandomUuid());
            osmOrderFlow.setStatus(new Byte("1"));
            osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setOperateUserName(reqAssignOrder.getOperate_staff_name());
            osmOrderFlow.setOrderId(orderId);
            osmOrderFlow.setOperateUserIcon(reqAssignOrder.getOperate_staff_icon());
            osmOrderFlowMapper.insertSelective(osmOrderFlow);

        }else if("2".equals(type)) {

            orderFailure.setStatus("16");
            osmOrderFailureMapper.updateByPrimaryKeySelective(orderFailure);

            orderFailure.setIsFromOut(1);
            orderFailure.setSubmitStaffId(orderFailure.getEnterpriseId());
            //生成派单企业的订单
            orderFailure.setEnterpriseId(reqAssignOrder.getTarget_id());
            orderFailure.setStatus("12");//待受理
            orderFailure.setTargetEnterpriseName("");
            orderFailure.setDepartmentId("");
            orderFailure.setTargetEnterpriseId("");
            orderFailure.setCreateTime(new Date());
            orderFailure.setModifyTime(new Date());
            orderFailure.setOutOrderId(orderFailure.getId());
            orderFailure.setId(UuidUtil.getRandomUuid());

            //// TODO: 2018/5/10 查询企业名称
//            orderFailure.setAcceptStaffName(reqAssignOrder.get);
            osmOrderFailureMapper.insertSelective(orderFailure);



            //记录操作流程节点
            OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
            osmOrderFlow.setSimpleDesc("外部派单:"+reqAssignOrder.getTarget_name());
            osmOrderFlow.setOperateUserId(reqAssignOrder.getOperate_staff_id());
            osmOrderFlow.setId(UuidUtil.getRandomUuid());
            osmOrderFlow.setStatus(new Byte("1"));
            osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setOperateUserName(reqAssignOrder.getOperate_staff_name());
            osmOrderFlow.setOrderId(orderId);
            osmOrderFlow.setOperateUserIcon(reqAssignOrder.getOperate_staff_icon());
            osmOrderFlowMapper.insertSelective(osmOrderFlow);


            //记录外部操作流程节点
            osmOrderFlow.setSimpleDesc(UserDataUtil.getUserSelectedEnterpriseName(request)+"外派工单");
            osmOrderFlow.setOperateUserId(reqAssignOrder.getOperate_staff_id());
            osmOrderFlow.setId(UuidUtil.getRandomUuid());
            osmOrderFlow.setStatus(new Byte("1"));
            osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setOperateUserName(reqAssignOrder.getOperate_staff_name());
            osmOrderFlow.setOrderId(orderFailure.getId());
            osmOrderFlow.setOperateUserIcon(reqAssignOrder.getOperate_staff_icon());
            osmOrderFlowMapper.insertSelective(osmOrderFlow);
        }

        LogCollector.INSTANCE.put("工单号",orderFailure.getOrderNbr());

//        收到指派工单【工单名称】，快去接单吧
        String content = "收到指派工单【"+orderFailure.getOrderTitle() +"】，快去接单吧";
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("order_type","1");
        jsonObject.addProperty("type","1");
        jsonObject.addProperty("order_id",orderFailure.getId());
        String extra = GsonUtil.toJson(jsonObject);
        String title = "收到派单";
        String sender = reqAssignOrder.getOperate_staff_id();
        String target = reqAssignOrder.getTarget_id();
        CreateNotifyReq createNotifyReq = new CreateNotifyReq(content,extra,title,sender,target,orderFailure.getEnterpriseId());

        notifyUtil.send(createNotifyReq);

    }

    @Override
    public void catchOrder(String orderId,String staffId,String name,String headIcon) {
        OsmOrderFailure orderFailure = osmOrderFailureMapper.selectByPrimaryKey(orderId);
        if(orderFailure.getStatus().equals("6")){
            // TODO: 2018/4/8 业务异常
        }else {
            orderFailure.setModifyTime(new Date());
            orderFailure.setStatus("6");//处理中
            orderFailure.setAcceptStaffId(staffId);
            orderFailure.setAcceptStaffName(name);
            orderFailure.setAcceptTime(new Date());
            osmOrderFailureMapper.updateByPrimaryKeySelective(orderFailure);

            //记录操作流程节点
            OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
            osmOrderFlow.setSimpleDesc("抢单成功");
            osmOrderFlow.setOperateUserId(staffId);
            osmOrderFlow.setId(UuidUtil.getRandomUuid());
            osmOrderFlow.setStatus(new Byte("1"));
            osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
            osmOrderFlow.setOperateUserName(name);
            osmOrderFlow.setOrderId(orderId);
            osmOrderFlow.setOperateUserIcon(headIcon);
            osmOrderFlowMapper.insertSelective(osmOrderFlow);
        }
        

    }

    @Override
    public void dealAgain(String orderId, String remark, String staffId, String name, String headIcon) {
        OsmOrderFailure orderFailure = osmOrderFailureMapper.selectByPrimaryKey(orderId);
        //退回、工单变为待处理状态
        //0草稿1审批中2审批不通过3待分配4待抢单5待接单6处理中7处理完成8已完成9已关闭10已退回11故障上报12待受理13撤回
        orderFailure.setStatus("6");
        orderFailure.setModifyTime(new Date());
        osmOrderFailureMapper.updateByPrimaryKeySelective(orderFailure);

        //记录操作流程节点
        OsmOrderFlow osmOrderFlow = new OsmOrderFlow();
        osmOrderFlow.setSimpleDesc("退回工单："+remark);
        osmOrderFlow.setOperateUserId(staffId);
        osmOrderFlow.setId(UuidUtil.getRandomUuid());
        osmOrderFlow.setStatus(new Byte("1"));
        osmOrderFlow.setCreateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setUpdateTime(Integer.valueOf(String.valueOf(System.currentTimeMillis()/1000)));
        osmOrderFlow.setOperateUserName(name);
        osmOrderFlow.setOrderId(orderId);
        osmOrderFlow.setOperateUserIcon(headIcon);
        osmOrderFlowMapper.insertSelective(osmOrderFlow);
    }
}
